<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Models\System;
use App\Http\Controllers\Controller;
use App\Handlers\ImageUploadHandler;

class SystemController extends Controller
{
    public function aboutus()
    {
        $list = System::first();
        $class = 'yu-system';
        $class_1 = 'system-aboutus';
        return view('admin.system.aboutus',compact('list','class','class_1'));
    }

    public function aboutus_edit($id)
    {
        $list = System::find($id);
        $class = 'yu-system';
        $class_1 = 'system-aboutus';
        return view('admin.system.aboutus_edit',compact('list','class','class_1'));
    }

    public function aboutus_update(Request $request,ImageUploadHandler $uploader,System $system,$id)
    {
        $data = $request->except('_token');
        if($request->image){
            $result = $uploader->save($request->image,'system');
            if($result){
                $data['image'] = $result['path'];
            }
        }
        if($system->updateData($id,$data)){
            return redirect('admin/system/aboutus')->with('success','更新成功');
        }else{
            return redirect('admin/system/aboutus')->with('danger','更新失败');
        }
    }
}
